package com.hongyuan.venue.ui.main.activity;

import android.os.Bundle;
import android.view.KeyEvent;

import androidx.lifecycle.ViewModelProviders;

import com.hongyuan.venue.R;
import com.hongyuan.venue.base.AppViewModelFactory;
import com.hongyuan.venue.base.CustomActivity;
import com.hongyuan.venue.databinding.ActivityCodeLoginBinding;
import com.hongyuan.venue.ui.main.view_mode.CodeLoginViewModel;
import com.hongyuan.venue.utils.CustomDialog;
import com.hongyuan.mvvmhabitx.base.AppManager;

import me.tatarka.bindingcollectionadapter2.BR;

public class CodeLoginActivity extends CustomActivity<ActivityCodeLoginBinding, CodeLoginViewModel> {

    @Override
    public int initContentView(Bundle savedInstanceState) {
        return R.layout.activity_code_login;
    }

    @Override
    public int initVariableId() {
        return BR.viewModel;
    }

    @Override
    public void initView() {
        super.initView();

        //开启拖动效果
        setOnRefresh(binding.refresh,REFRESH_0X4);
    }

    @Override
    public CodeLoginViewModel initViewModel() {
        //使用自定义的ViewModelFactory来创建ViewModel，如果不重写该方法，则默认会调用LoginViewModel(@NonNull Application application)构造方法
        AppViewModelFactory factory = AppViewModelFactory.getInstance(getApplication());
        return ViewModelProviders.of(this, factory).get(CodeLoginViewModel.class);
    }

    //安卓重写返回键事件
    @Override
    public boolean onKeyDown(int keyCode, KeyEvent event) {
        if(keyCode==KeyEvent.KEYCODE_BACK){
            CustomDialog.promptDialog(this, "确定要退出程序？", "确定", "取消", false, v -> {
                if(v.getId() == R.id.isOk){
                    AppManager.getAppManager().finishAllActivity();
                }
            });
            return false;
        }
        return true;
    }

}
